<template>
	<view class="content">
		<view class="admin-box">
			<button type="primary" @click="shanku">清空问题列表（删库，慎用）</button>
		</view>
		<text v-if="isAnswerList" class="no-answer-txt">
			待审核列表为空
		</text>
		<view class="list-box" v-else>
			<view class="list-item" v-for="(i,index) in arr" :key="index">
				<view class="answer-box" >
					{{i.answer}}
				</view>
				<view class="zan-box1" @click="jujue(i._id)">
					拒绝
				</view>
				<view class="zan-box" @click="tongguo(i._id)">
					通过
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				arr:[],
				isAnswerList:false
			};
		},
		onShow() {
			this.getList()
		},
		methods:{
			shanku(){
				uni.showModal({
					content:'确定删库么？',
					success: (res) => {
						if(res.confirm){
							uniCloud.callFunction({
								name:'supportShanKu'
							}).then((res)=>{
								this.getList()
							})
						}
					}
				})
			},
			getList(){
				uni.showLoading({
					title:'加载中···',
					mask:true
				})
				uniCloud.callFunction({
					name:'supportGetState'
				}).then((res)=>{
					uni.hideLoading()
					if (res.result.data.length>0) {
						this.isAnswerList = false
					} else{
						this.isAnswerList = true
					}
					this.arr = res.result.data
					console.log(this.arr)
				})
			},
			tongguo(id){
				uni.showLoading({
					title:'提交中···',
					mask:true
				})
				
				uniCloud.callFunction({
					name:'supportChangeState',
					data:{id:id}
				}).then((res)=>{
					uni.hideLoading()
					if (res.result.updated==1) {
						this.getList()
					}
					console.log(res)
				})
			},
			jujue(id){
				uni.showLoading({
					title:'提交中···',
					mask:true
				})
				
				uniCloud.callFunction({
					name:'supportJujue',
					data:{id:id}
				}).then((res)=>{
					uni.hideLoading()
					if (res.result.updated==1) {
						this.getList()
					}
					console.log(res)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background: #F8F8F8;
	}
.no-answer-txt{
		font-size: 40rpx;
		color: #cc0000;
		font-weight: bold;
		margin-top: 50rpx;
	}
	.list-box{
		margin-top: 60rpx;
	}
	.list-item{
		width: 700rpx;
		// height: 70rpx;
		background: #fff;
		min-height: 70rpx;
		border: 2px solid #808080;
		border-radius: 15rpx;
		display: flex;
		flex-direction: row;
		margin-bottom: 24rpx;
		view{
			// height: 100% !important;
			color: #000;
			font-size: 28rpx;
		}
		.answer-box{
			padding: 10rpx 0;
			width: 60%;
			height: 100% !important;
			line-height: 46rpx;
			padding-left: 15rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
		}
		.zan-box{
			// height: 100% !important;
			width: 20%;
			border-left: 2px solid #808080;
			color: #fff;
			text-align: center;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			background: #007AFF;
		}
		.zan-box1{
			// height: 100% !important;
			width: 20%;
			border-left: 2px solid #808080;
			color: #fff;
			text-align: center;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			background: #DD524D;
		}
	}
	.admin-box{
		// border: 1px solid #DD524D;
		border-radius: 20rpx;
		width: 90%;
		margin-top: 20rpx;
	}
</style>
